package com.example.test_app

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.hardware.input.InputManager
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.example.test_app.Util.ClassCopier
import com.example.test_app.adapter.DemoAdapter
import com.example.test_app.bean.Cjp
import kotlinx.coroutines.*
import java.lang.reflect.Method
import java.lang.reflect.Proxy
import java.util.*

class DemoListActivity : AppCompatActivity() {
    val TAG = "DemoListActivity"
    var rv: RecyclerView? = null
    var data = ArrayList<DemoAdapter.DemoBean>()
    var adapter: DemoAdapter? = null
    var cjp = Cjp()

    interface AA {
        fun startActivity(intent: Intent?, options: Bundle?)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_demo_list)
        rv = findViewById(R.id.rv_test)
        adapter = DemoAdapter(this, data)
        rv?.layoutManager = LinearLayoutManager(this)
        rv?.adapter = adapter
        initData()
        adapter?.notifyDataSetChanged()


    }

    override fun startActivity(intent: Intent?, options: Bundle?) {
        super.startActivity(intent, options)
    }

    private fun initData() {
        data.add(DemoAdapter.DemoBean("MainActivity") {
            val activity=object:Activity(){
                override fun startActivity(intent: Intent?) {
                    super.startActivity(intent)
                    Log.d(TAG, "startActivity: 123")
                }
            }
            Log.d(TAG, "initData:  ac="+activity.hashCode())
            var c=ClassCopier(Activity::class.java)
            c.copy(this@DemoListActivity,activity)
            Log.d(TAG, "initData: this@DemoListActivity="+this@DemoListActivity.hashCode())
            Log.d(TAG, "initData: copy ac="+activity.hashCode())

            activity.startActivity(Intent(this, MainActivity::class.java))

        })
        data.add(DemoAdapter.DemoBean("VpActivity") {
            startActivity(Intent(this, VpActivity::class.java))
        })
        data.add(DemoAdapter.DemoBean("MainActivity2") {
            startActivity(Intent(this, MainActivity2::class.java))
        })
        data.add(DemoAdapter.DemoBean("RvActivity") {
            startActivity(Intent(this, RvActivity::class.java))
        })
        data.add(DemoAdapter.DemoBean("FragmentContainerViewActivity") {
            startActivity(Intent(this, FragmentContainerViewActivity::class.java))
        })
    }

    override fun startActivity(intent: Intent?) {
        super.startActivity(intent)
        Log.d(TAG, "startActivity: ac")
    }

    override fun onResume() {
        super.onResume()

    }


}